<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class MyPromise {
            constructor(handle) {
                this['[[PromiseState]]'] = 'pending';
                this['[[PromiseResult]]'] = undefined;
                handle(this._resolve.bind(this),this._reject.bind(this))
            }
            _resolve(val) {
                if(this['[[PromiseState]]'] === 'pending'){
                this['[[PromiseState]]'] = 'fulfilled';
                this['[[PromiseResult]]'] = val;
            }
            }
            _reject(err) {
                if(this['[[PromiseState]]'] === 'pending'){
                this['[[PromiseState]]'] = 'rejected';
                this['[[PromiseResult]]'] = err;
                }
            }
            then(){
                // return this;// 不停返回自身
                // return new MyPromise()// 返回新对象
            }
        }
        let p = new MyPromise((resolve,reject)=>{
            reject('失败')
            resolve('成功');
        })
        console.log(p);
    </script>
</body>

</html>